package com.itheima.d9_test02;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;

public class demo02 {
    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("hero.txt", Charset.forName("GBK"));
        BufferedReader br = new BufferedReader(fr);
        ArrayList<Hero> heroes = new ArrayList<>();
        String line;
        String head = br.readLine();

        while((line = br.readLine()) != null){
            String[] split = line.split(",+");
//            System.out.println(Arrays.toString(split));
            heroes.add(new Hero(split[0],Integer.parseInt(split[1]),Integer.parseInt(split[2]),Integer.parseInt(split[3])));
        }
//        for (Hero hero : heroes) {
//            System.out.println(hero);
//        }

        FileWriter fw = new FileWriter("demo03.txt");
        BufferedWriter bw = new BufferedWriter(fw);
        heroes.sort(((o1, o2) -> Double.compare(o2.getScore(),o1.getScore())));

        bw.write(head+" 上手度");
        for (Hero hero : heroes) {
            String s = hero.toString();
            System.out.println(s);
            bw.write(System.lineSeparator()+s);
        }

        br.close();
        bw.close();

    }
}
